package com.jms.fu.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jms.fu.exception.DAOException;
import com.jms.fu.model.bean.App;
import com.jms.fu.model.bo.AppBO;

public class DownloadAppAction extends Action{

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		PrintWriter out;
		try {
			out = response.getWriter();
			int appid = Integer.parseInt(request.getParameter("appid"));
			AppBO appbo = new AppBO();
			App app = appbo.getAppByID(appid);
			float price = app.getPrice();
			if(price==0){
				String appname = appbo.getNumberOfFile(getServlet()
						.getServletContext().getRealPath("/")+app.getLink()).get(0);
				out.print(app.getLink()+"/"+appname);
			}
			return null;
		} catch (IOException | DAOException e) {
			e.printStackTrace();
			return null;
		}
		
		
		
	}
	
}
